<template>
  <j-modal :title="title" :width="width" :visible="visible" switchFullscreen @ok="submitForm"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }" @cancel="handleCancel" cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <j-form-container :disabled="formDisabled">
        <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
          <a-row>
            <a-col :span="24">
              <a-form-model-item label="门店登录账号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="loginAccount">
                <a-input v-model="model.loginAccount" placeholder="请输入门店登录账号"></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="门店名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="merchantName">
                <a-input v-model="model.merchantName" placeholder="请输入门店名称"></a-input>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </j-form-container>


    </a-spin>
  </j-modal>
</template>

<script>
import { httpAction } from '@/api/manage'
export default {
  name: 'HcMerchantModalCopyThis',
  props: {
    // 表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false,
    },
  },
  data() {
    return {
      title: '',
      width: 1260,
      visible: false,
      disableSubmit: false,
      model: {},
      confirmLoading: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      validatorRules: {
        merchantName: [{ required: true, message: '请输入门店名称!' }],
        loginAccount: [
          { required: true, message: '请输入门店登录账号!' },
          {
            validator: (rule, value, callback) => {
              if (!value) {
                callback()
              } else {
                var reg_tel = /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/;    //11位手机号码正则
                if (!reg_tel.test(value)) {
                  console.log('5555')
                  callback('请输入正确格式的手机号码!')
                } else {
                  callback();
                }
              }
            },
          },
        ],
      },
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  methods: {
    edit(record) {
      console.log('record', record);
      this.model = {...record}
      this.visible = true;
    },
    handleCancel() {
      this.visible = false;
    },

    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate((valid) => {

        if (valid) {
          that.confirmLoading = true;
          let httpurl = '/hc/hcMerchant/copyMerchant';
          httpAction(httpurl, this.model, 'post')
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.handleCancel();
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    },
    
  }
}
</script>